/*-----------------------------------------------------------------------
								 \\\|///
							   \\  - -  //
								(  @ @  )  
+-----------------------------oOOo-(_)-oOOo-----------------------------+
CONFIDENTIAL IN CONFIDENCE
This confidential and proprietary software may be only used as authorized
by a licensing agreement from CrazyBingo (Thereturnofbingo).
In the event of publication, the following notice is applicable:
Copyright (C) 2012-20xx CrazyBingo Corporation
The entire notice above must be reproduced on all authorized copies.
Author				:		CrazyBingo
Technology blogs 	: 		http://blog.chinaaet.com/crazybingo
Email Address 		: 		thereturnofbingo@gmail.com
Filename			:		KEY_Scan_Design.v
Data				:		2013-10-22
Description			:		Design for Key scan.
Modification History	:
Data			By			Version			Change Description
=========================================================================
13/10/27		CrazyBingo	1.0				Original
-------------------------------------------------------------------------
|                                     Oooo								|
+-------------------------------oooO--(   )-----------------------------+
                               (   )   ) /
                                \ (   (_/
                                 \_)
-----------------------------------------------------------------------*/

`timescale 1ns/1ns
module KEY_Scan_Design
(
	//global clock
	input				clk,
	input				rst_n,
	
	//user interface
	input		[3:0]	key_data,	
	
	//74595 led interface
	output				led595_dout,	//74hc595 serial data input	
	output				led595_clk,		//74hc595 shift clock (rising edge)
	output				led595_latch	//74hc595 latch clock (rising edge)
);


//----------------------------------
//Key scan with jitter detect
wire			key_flag;
wire	[3:0]	key_value;
key_jitter_scan		
#(
	.KEY_WIDTH	(4)
)
u_key_jitter_scan
(
	//global
	.clk				(clk),
	.rst_n				(rst_n),
	
	//key interface
	.key_data			(key_data),		
	
	//user interface
	.key_flag			(key_flag),
	.key_value			(key_value)	
);


//---------------------------------
//led data input with enable signal.
wire	[7:0]	led_data;
led_input_display
#(
	.LED_WIDTH	(8)
)
u_led_input_display
(
	//global
	.clk				(clk),
	.rst_n				(rst_n),
	
	//user interface
	.led_en				(key_flag),
	.led_value			({{2{key_value[3]}}, {2{key_value[2]}}, {2{key_value[1]}}, {2{key_value[0]}}}),
	
	//led interface
	.led_data			(led_data)
);

//---------------------------
//The driver of 74HC595
led_74595_driver	u_led_74595_driver
(
	//global clock
	.clk				(clk),
	.rst_n				(rst_n),

	//74hc595 interface
	.led595_dout		(led595_dout),	//74hc595 serial data input	
	.led595_clk			(led595_clk),	//74hc595 shift clock (rising edge)
	.led595_latch		(led595_latch),	//74hc595 latch clock (risign edge)

	//user interface
	.led_data			(led_data)		//led data input	
);


endmodule


